package com.foosun.core.service;

import com.foosun.core.base.BaseDao;
import com.foosun.core.base.BaseService;
import com.foosun.core.base.PageData;
import com.foosun.core.dao.ResourceDao;
import com.foosun.core.entity.Role;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Nelin on 14-2-21.
 */
@Service
@Transactional
public class RoleService extends BaseService<Role> {

    @Override
    @javax.annotation.Resource(name = "roleDao")
    public void setBaseDao(BaseDao<Role> baseDao) {
        this.baseDao = baseDao;
    }

    @javax.annotation.Resource
    private ResourceDao resourceDao;


    @Override
    public PageData<Role> findList(PageData<Role> pageData) throws Exception {
        pageData = super.findList(pageData);
        List<Role> roles = pageData.getResult();
        for (Role role : roles) {
            role.setScopeData(resourceDao.getResourceMapByIds(role.getScope()));
//            role.setScope(resourceDao.getResourceNamesByIds(role.getScope()));
        }
        return pageData;
    }
}
